package com.jxmcloud.business.cut.service.impl.database;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jxmcloud.business.cut.json.DataConfigStartLoader;
import com.jxmcloud.business.cut.mapper.database.IUserGainAwardRecordDBMapper;
import com.jxmcloud.business.cut.model.database.DBUserGainAwardRecord;
import com.jxmcloud.business.cut.service.database.IUserGainAwardRecordDBService;
import com.jxmcloud.business.cut.util.SerialNumberUtil;
import com.jxmcloud.business.cut.vo.json.ConfigStartVo;
import com.jxmcloud.business.cut.vo.user.PlayerInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class UserGainAwardRecordDBServiceImpl extends ServiceImpl<IUserGainAwardRecordDBMapper, DBUserGainAwardRecord> implements IUserGainAwardRecordDBService {
    @Autowired
    private DataConfigStartLoader dataConfigStartLoader;

    @Override
    public boolean insertIntoData(PlayerInfoVo player) {
        DBUserGainAwardRecord record = new DBUserGainAwardRecord();
        Integer activityStartId = player.getActivity().getStartId();
        ConfigStartVo configStart = dataConfigStartLoader.getConfigById(activityStartId);
        Integer gold = configStart.getGold();   //获取金额

        record.setUid(player.getBase().getUid());
        record.setActivityId(player.getActivity().getActivityId());
        record.setGold(gold.longValue());
        record.setStatus(0);
        record.setOrderNo(SerialNumberUtil.autoOrderNo());
        record.setCreateTime(new Date());
        record.setUpdateTime(new Date());

        return this.baseMapper.insert(record) == 1;
    }
}
